<template>
  <p-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">

        <p-form-item label="标准端编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'standardNo', validatorRules.standardNo]" placeholder="请输入标准端编码"></p-input>
        </p-form-item>
        <p-form-item label="标准端名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'standardName', validatorRules.standardName]" placeholder="请输入标准端名称"></p-input>
        </p-form-item>
        <p-form-item label="标准端版次" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'standardVersion', validatorRules.standardVersion]" placeholder="请输入标准端版次"></p-input>
        </p-form-item>
        <p-form-item label="标准端SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'standardSn', validatorRules.standardSn]" placeholder="请输入标准端SN"></p-input>
        </p-form-item>
        <p-form-item label="工单" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'morderno', validatorRules.morderno]" placeholder="请输入工单"></p-input>
        </p-form-item>
        <p-form-item label="校准类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['calibrationType', validatorRules.calibrationType]" :trigger-change="true" dictCode="mes_calibration_type" placeholder="请选择校准类型"/>
        </p-form-item>
        <p-form-item label="要求完成日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择要求完成日期" v-decorator="[ 'reqdt', validatorRules.reqdt]" :trigger-change="true" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="申请日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择申请日期" v-decorator="[ 'applyTime', validatorRules.applyTime]" :trigger-change="true" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'applyBy', validatorRules.applyBy]" placeholder="请输入申请人"></p-input>
        </p-form-item>
        <p-form-item label="校准人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'calibrateBy', validatorRules.calibrateBy]" placeholder="请输入校准人"></p-input>
        </p-form-item>
        <p-form-item label="校准时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择校准时间" v-decorator="[ 'calibrateDt', validatorRules.calibrateDt]" :trigger-change="true" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="校准记录" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-upload v-decorator="['calibrateRecord', validatorRules.calibrateRecord]" :trigger-change="true"></j-upload>
        </p-form-item>
        <p-form-item label="产品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <f-popup
            contextPath="basic-business"
            v-decorator="['mcode', validatorRules.mcode]"
            :trigger-change="true"
            org-fields="id,mcode,mname,sprc,mexplain"
            dest-fields="mid,mcode,mname,sprc,mexplain"
            code="wms_cpinfo"
            @callback="popupCallback"/>
        </p-form-item>
        <p-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'mname', validatorRules.mname]" placeholder="请输入产品名称"></p-input>
        </p-form-item>

      </p-form>
    </p-spin>
    <p-button type="primary" @click="handleOk">确定</p-button>
    <p-button type="primary" @click="handleCancel">取消</p-button>
  </p-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JUpload from '@/components/jeecg/JUpload'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  
  export default {
    name: "MesEqStandardCalibrationrecordModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDate,
      JUpload,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          standardNo: {rules: [
            {required: true, message: '请输入标准端编码!'},
          ]},
          standardName: {rules: [
            {required: true, message: '请输入标准端名称!'},
          ]},
          standardVersion: {rules: [
            {required: true, message: '请输入标准端版次!'},
          ]},
          standardSn: {rules: [
            {required: true, message: '请输入标准端SN!'},
          ]},
          morderno: {rules: [
            {required: true, message: '请输入工单!'},
          ]},
          calibrationType: {rules: [
            {required: true, message: '请输入校准类型!'},
          ]},
          reqdt: {rules: [
            {required: true, message: '请输入要求完成日期!'},
          ]},
          applyTime: {rules: [
          ]},
          applyBy: {rules: [
          ]},
          calibrateBy: {rules: [
          ]},
          calibrateDt: {rules: [
            {required: true, message: '请输入校准时间!'},
          ]},
          calibrateRecord: {rules: [
          ]},
          mcode: {rules: [
            {required: true, message: '请输入产品编码!'},
          ]},
          mname: {rules: [
            {required: true, message: '请输入产品名称!'},
          ]},
        },
        url: {
          add: '/mes-equipment/auto/mesEqStandardCalibrationrecord/add',
          edit: '/mes-equipment/auto/mesEqStandardCalibrationrecord/edit',
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },

      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'standardNo','standardName','standardVersion','standardSn','morderno','calibrationType','reqdt','applyTime','applyBy','calibrateBy','calibrateDt','calibrateRecord','mcode','mname'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
              that.confirmLoading = true;
              let httpurl = '';
              let method = '';
              let formData = Object.assign(this.model, values);
              this.formData = Object.assign(this.model, values);
              //新增触发
              if(!this.model.id){
                httpurl+=this.url.add;
                method = 'post';
                if(this.EnhanceJS.afterAdd){
                  //新增之前
                  let Obj = eval(this.EnhanceJS.afterAdd)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }else{
                //编辑触发
                httpurl+=this.url.edit;
                method = 'put';
                if(this.EnhanceJS.afterEdit){
                 //编辑之前
                  let Obj = eval(this.EnhanceJS.afterEdit)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'standardNo','standardName','standardVersion','standardSn','morderno','calibrationType','reqdt','applyTime','applyBy','calibrateBy','calibrateDt','calibrateRecord','mcode','mname'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>
